
module Wiki
  class WikiText < Content::TextField

    def format text
      format_pre_els(super(text))
    end

    def render
      context.page.link_css file_url('syntax.css')
      super
    end

  protected

    def format_pre_els(html)
      c = Syntax::Convertors::HTML.for_syntax "ruby"
      
      Hpricot(html).search('//pre') { |e|
        e.inner_html = c.convert(e.inner_text, false)
        e.set_attribute 'class', "ruby"
      }.to_s
    end

  end
end